#测试帖子详情页
import time

from selenium.webdriver.common.by import By

from commond.Utils import ForumDriver
from Test.ForumListTest import List
from Test.ForumLoginTest import Login
class ForumDetail:
    url=""
    driver=""
    def __init__(self):
        self.driver=ForumDriver.driver
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)

    #检查头部导航条，这里有 BUG
    def Detail_Head(self):
        List.Check_Head()

    #未登录情况下，查看帖子详情页
    def Fail_Detail(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)
        #返回登陆页面
        Login.Check_Ele_Login()

    #有关原帖的检查
    def Check_Detail_pos(self):
    #原帖的属性
        #标题
        # txt= self.driver.find_element(By.CSS_SELECTOR,"#details_article_title").text
        # assert txt=="mxj测试"

        #点赞
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count")
        #发私信
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message")

    #原帖的内容
        text=self.driver.find_element(By.CSS_SELECTOR,"#details_article_content > p").text
        print(text)

    #测试发送私信功能
    def Send_msg(self):
        #点击私信按钮
        self.driver.find_element(By.CSS_SELECTOR,"#btn_details_send_message").click()
        #出现输入文本弹窗一个取消按钮，一个发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_content").send_keys("你好")
        time.sleep(2)
        #取消发送
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_receive_cancel").click()
        time.sleep(5)

        #正确发送私信????
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_receive_content").send_keys("你好你好")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message").click()

    #检查私信是否成功发送
    def Check_msg(self):
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver.get(self.url)
        #登陆这个账号
        Login.Suc_Login_mxj2()
        time.sleep(2)
        #点击通知
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        #点击私信
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a").click()
        #截屏
        ForumDriver.getScreenshot()
        time.sleep(1)
        #点击取消按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_cancel").click()

        #回复私信测试
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_receive_content").send_keys("收到")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message_reply")
        time.sleep(2)

        #关闭通知
        # self.driver.find_element(By.CSS_SELECTOR,"#index_message_offcanvasEnd > div.offcanvas-header > button").click()
        # index_message_offcanvasEnd > div.offcanvas-header > button
        #返回登陆页面
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver.get(self.url)

    #进入帖子编辑页测试
    def Detail_To_Edit(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        txt=self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2").text
        assert txt=="发新贴"







Datail=ForumDetail()



